package com.pankaj;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import com.pankaj.R;

public class ListimagesfromserverActivity extends Activity {
	// private String language[];
	// private String language_id[];
	// private String language_name[];
	// private String language_flage[];
	// private String state_id[];
	// private String state_name[];
	ListView list;
	LazyAdapter adapter;
	// private String path[];
	xml_store store;
	ProgressDialog mDialog = null; // thread code
	private Runnable viewOrders; // thread code
	private Thread thread1;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.m_list);

		mDialog = new ProgressDialog(this); // thread code
		mDialog.setMessage("Please wait...");
		
		store = new xml_store(this);
		viewOrders = new Runnable() {
			public void run() {
				store.load();
				runOnUiThread(returnRes);
			}
		};
		thread1 = new Thread(null, viewOrders, "Background"); // thread
		thread1.start(); // thread code
		mDialog.show();

	}

	private Runnable returnRes = new Runnable() {
		public void run() {
			mDialog.cancel();
			for (int i = 0; i < store.img_url.length; i++) {
				System.out.println("img url :- " + store.img_url[i]);
			}

			list = (ListView) findViewById(R.id.list);
			adapter = new LazyAdapter(ListimagesfromserverActivity.this,store.img_url, store.s_name);
			list.setAdapter(adapter);
		}
	};
	// public class xmlNews {
	// String res1;
	// InputStream is;
	// StringBuilder sb;
	//
	//
	// public void load() {
	// Document doc = null;
	// HttpURLConnection urlConnection = null;
	// URL url = null;
	// try {
	// // url = new URL(constant.urlNews.toString());
	// url = new
	// URL("http://www.worldwide-marketplace.com/iphone/interface_sprach_land_region.php");
	// urlConnection = (HttpURLConnection) url.openConnection();
	// urlConnection.setRequestMethod("GET");
	// urlConnection.setDoOutput(true);
	// urlConnection.setDoInput(true);
	// urlConnection.connect();
	// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	// DocumentBuilder db = dbf.newDocumentBuilder();
	// doc = db.parse(urlConnection.getInputStream());
	// } catch (Exception e) {
	// System.out.println("e" + e.toString());
	// }
	// try {
	// NodeList nodes = doc.getElementsByTagName("language");
	// language_id = new String[nodes.getLength()];
	// language_name = new String[nodes.getLength()];
	// language_flage = new String[nodes.getLength()];
	// for (int i = 0; i < nodes.getLength(); i++) {
	// Element element = (Element) nodes.item(i);
	//
	// NodeList id = element.getElementsByTagName("sprachid");
	// Element line = (Element) id.item(0);
	// language_id[i] = getCharacterDataFromElement(line);
	//
	// NodeList detail = element.getElementsByTagName("sprachname");
	// line = (Element) detail.item(0);
	// language_name[i] = getCharacterDataFromElement(line);
	//
	// NodeList flag = element.getElementsByTagName("flagge");
	// line = (Element) flag.item(0);
	// language_flage[i] = getCharacterDataFromElement(line);
	// }
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	//
	// try {
	//
	// NodeList nodes1 = doc.getElementsByTagName("staat");
	// state_id = new String[nodes1.getLength()];
	// state_name = new String[nodes1.getLength()];
	// for (int i = 0; i < nodes1.getLength(); i++) {
	// Element element = (Element) nodes1.item(i);
	//
	// NodeList sid = element.getElementsByTagName("staatid");
	// Element line = (Element) sid.item(0);
	// state_id[i] = getCharacterDataFromElement(line);
	//
	// NodeList sdetail = element.getElementsByTagName("staatname");
	// line = (Element) sdetail.item(0);
	// state_name[i] = getCharacterDataFromElement(line);
	// }
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// }
	//
	// public String getCharacterDataFromElement(Element e) {
	// Node child = e.getFirstChild();
	// if (child instanceof CharacterData) {
	// CharacterData cd = (CharacterData) child;
	// return cd.getData();
	// }
	// return "?";
	// }
	// }
}